//-
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

include /app/helpers/jade/mixins
include /app/configuration/mixins

-var form = 'checkpoint'
-var model = '$ctrl.clonedCluster.checkpointSpi'
-var CustomCheckpoint = '$checkpointSPI.kind === "Custom"'
-var CacheCheckpoint = '$checkpointSPI.kind === "Cache"'

panel-collapsible(ng-form=form)
    panel-title Checkpointing
    panel-description
        | Checkpointing provides an ability to save an intermediate job state.
        | #[a.link-success(href="https://apacheignite.readme.io/docs/checkpointing" target="_blank") More info]
    panel-content.pca-form-row
        .pca-form-column-6.pc-form-grid-row
            .pc-form-grid-col-60
                .ignite-form-field
                    +form-field__label({ label: 'Checkpoint SPI configurations:', name: '"checkpointSPIConfigurations"' })

                    list-editable.pc-list-editable-with-form-grid(ng-model=model name='checkpointSPIConfigurations')
                        list-editable-item-edit(item-name='$checkpointSPI').pc-form-grid-row
                            .pc-form-grid-col-60
                                +form-field__dropdown({
                                    label: 'Checkpoint SPI:',
                                    model: '$checkpointSPI.kind',
                                    name: '"checkpointKind"',
                                    required: 'true',
                                    placeholder: 'Choose checkpoint configuration variant',
                                    options: '[\
                                                {value: "FS", label: "File System"},\
                                                {value: "Cache", label: "Cache"},\
                                                {value: "S3", label: "Amazon S3"},\
                                                {value: "JDBC", label: "Database"},\
                                                {value: "Custom", label: "Custom"}\
                                               ]',
                                    tip: 'Provides an ability to save an intermediate job state\
                                          <ul>\
                                            <li>File System - Uses a shared file system to store checkpoints</li>\
                                            <li>Cache - Uses a cache to store checkpoints</li>\
                                            <li>Amazon S3 - Uses Amazon S3 to store checkpoints</li>\
                                            <li>Database - Uses a database to store checkpoints</li>\
                                            <li>Custom - Custom checkpoint SPI implementation</li>\
                                          </ul>'
                                })

                            include ./checkpoint/fs

                            .pc-form-grid-col-60(ng-if-start=CacheCheckpoint)
                                +form-field__dropdown({
                                    label: 'Cache:',
                                    model: '$checkpointSPI.Cache.cache',
                                    name: '"checkpointCacheCache"',
                                    required: CacheCheckpoint,
                                    placeholder: 'Choose cache',
                                    placeholderEmpty: 'No caches configured for current cluster',
                                    options: '$ctrl.cachesMenu',
                                    tip: 'Cache to use for storing checkpoints'
                                })(
                                    pc-is-in-collection='$ctrl.clonedCluster.caches'
                                )
                                    +form-field__error({ error: 'isInCollection', message: `Cluster doesn't have such a cache` })
                            .pc-form-grid-col-60(ng-if-end)
                                +form-field__java-class({
                                    label: 'Listener:',
                                    model: '$checkpointSPI.Cache.checkpointListener',
                                    name: '"checkpointCacheListener"',
                                    tip: 'Checkpoint listener implementation class name',
                                    validationActive: CacheCheckpoint
                                })

                            include ./checkpoint/s3

                            include ./checkpoint/jdbc

                            .pc-form-grid-col-60(ng-if=CustomCheckpoint)
                                +form-field__java-class({
                                    label: 'Class name:',
                                    model: '$checkpointSPI.Custom.className',
                                    name: '"checkpointCustomClassName"',
                                    required: CustomCheckpoint,
                                    tip: 'Custom CheckpointSpi implementation class',
                                    validationActive: CustomCheckpoint
                                })

                        list-editable-no-items
                            list-editable-add-item-button(
                                add-item=`$edit($ctrl.Clusters.addCheckpointSPI($ctrl.clonedCluster))`
                                label-single='checkpoint SPI configuration'
                                label-multiple='checkpoint SPI configurations'
                            )

        .pca-form-column-6
            +preview-xml-java('$ctrl.clonedCluster', 'clusterCheckpoint', '$ctrl.caches')
